#pragma once
#include<iostream>
#include<string>

std::string opers="+-*/%";

enum
{
    DivZero=1,
    ModZero,
    Unknown
};

class Task
{
public:
    Task()
    {}
    Task(int x,int y,char op):data1_(x),data2_(y),oper_(op)
    {
        result_=0;
        exitcode_=0;
    }
    void run()
    {
        switch(oper_)//判断方法
        {
            case '+':
                result_ = data1_ + data2_;
                break;
            case '-':
                result_ = data1_ - data2_;
                break;
            case '*':
                result_ = data1_ * data2_;
                break;
            case '/':
                {
                    if(data2_ == 0) exitcode_ = DivZero;
                    else result_ =data1_/data2_;
                }
                break;
            case '%':
                {
                    if(data2_ == 0) exitcode_ = ModZero;
                    else result_ = data1_ % data2_;
                }
                break;
            default:
                exitcode_ = Unknown;
                break;

        }
    }
    //函数重载
    void operator()()
    {
        run();
    }
    std::string GetResult()
    {
        std::string r = std::to_string(data1_);
        r +=oper_;
        r +=std::to_string(data2_);
        r +="=";
        r +=std::to_string(result_);
        r +=" [";
        r +="code:";
        r +=std::to_string(exitcode_);
        r +="]";
        return r;
    }

    std::string GetTask()//获取任务结构
    {
        std::string r = std::to_string(data1_);
        r +=oper_;
        r +=std::to_string(data2_);
        r +="=?";
        return r;
    }

    ~Task()
    {

    }
private:
    int data1_;      //数据
    int data2_;
    char oper_;    //运算方法

    int result_; //结果
    int exitcode_;//退出码
};